package com.ruoyi.petSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.petSys.domain.AddFriend;
import com.ruoyi.petSys.entity.vo.AttentionVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.petSys.domain.Attention;
import com.ruoyi.petSys.service.IAttentionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 好友列表Controller
 * 
 * @author ruoyi
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/petSys/attention")
public class AttentionController extends BaseController
{
    @Autowired
    private IAttentionService attentionService;

    /**
     * 查询好友列表列表
     */
//    @PreAuthorize("@ss.hasPermi('petSys:attention:list')")
    @GetMapping("/list")
    public TableDataInfo list(Attention attention)
    {
        startPage();
        List<AttentionVo> list = attentionService.selectAttentionList(attention);
        return getDataTable(list);
    }

    /**
     * 导出好友列表列表
     */
//    @PreAuthorize("@ss.hasPermi('petSys:attention:export')")
    @Log(title = "好友列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Attention attention)
    {
        List<AttentionVo> list = attentionService.selectAttentionList(attention);
        ExcelUtil<AttentionVo> util = new ExcelUtil<AttentionVo>(AttentionVo.class);
        util.exportExcel(response, list, "好友列表数据");
    }

    /**
     * 获取好友列表详细信息
     */
//    @PreAuthorize("@ss.hasPermi('petSys:attention:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attentionService.selectAttentionById(id));
    }

    /**
     * 新增好友列表
     */
//    @PreAuthorize("@ss.hasPermi('petSys:attention:add')")
    @Log(title = "好友列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Attention attention)
    {
        return toAjax(attentionService.insertAttention(attention));
    }

    /**
     * 修改好友列表
     */
//    @PreAuthorize("@ss.hasPermi('petSys:attention:edit')")
    @Log(title = "好友列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Attention attention)
    {
        return toAjax(attentionService.updateAttention(attention));
    }

    /**
     * 删除好友列表
     */
//    @PreAuthorize("@ss.hasPermi('petSys:attention:remove')")
    @Log(title = "好友列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attentionService.deleteAttentionByIds(ids));
    }


    @GetMapping("/selectNotAttentionUserList")
    public  TableDataInfo selectNotAttentionUserList(@RequestParam("nickName")String nickName){
        List<SysUser> sysUsers = attentionService.selectNotAttentionUserList(nickName);
        return getDataTable(sysUsers);

    }


    /**
     * 同意好友申请
     * @param addFriend
     * @return
     */
    @PostMapping("/updateFriendApply")
    public AjaxResult updateFriendApply(@RequestBody AddFriend addFriend){

        attentionService.updateFriendApply(addFriend);
        return success();
    }
    /**
     * 添加对方为好友
     * @param addFriend
     * @return
     */
    @PostMapping("/addFriendById")
    public AjaxResult addFriendById(@RequestBody AddFriend addFriend){

        attentionService.addFriendById(addFriend);
        return success();
    }


}
